# _*_coding:utf-8 _*_
# @Time　　:2021/1/31 16:58
# @Author　 : wangyong
# @File　　  :setting.py
# @Software  :PyCharm
from ApiTest.api.base_api import BaseApi
from ApiTest.conf.config import online_host
from ApiTest.utils.log import get_log

log = get_log("setting")


class Setting(BaseApi):
    url = online_host + "api/v2/user/setting"
    headers = {
        "Content-Type": "application/json;charset=UTF-8",
        "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, "
                      "like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1 "
    }

    def setting(self, method: str, json=None, params=None, data=None):
        method = method.upper()
        try:
            if method == "GET":
                log.info("开始进行setting接口调用，调用URL为：{}".format(self.url))
                res = self.send_request_session(method="get", url=self.url, params=params)
                log.info("返回接口数据为：{}".format(res.json()))
                return res.json()
            elif method == "POST":
                log.info("开始进行登录接口调用，调用URL为：{}".format(self.url))
                res = self.send_request_session(method="post",
                                                url=self.url,
                                                data=data,
                                                json=json,
                                                headers=self.headers)
                log.info("返回接口数据为：{}".format(res.json()))
                return res.json()
        except Exception as e:
            log.info("接口出现异常：{}".format(e))
